package sample;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;

import java.net.URL;
import java.util.ResourceBundle;

public class SearchTeacherTtbleController implements Initializable {

    @FXML
    private Button showSchedule;

    @FXML
    private Button searchRommTable;

    @FXML
    private Button SearchTecherTable;

    @FXML
    private Button ClassNote;

    @FXML
    private TableView<CouseList> Ttble;

    @FXML
    private TableColumn<CouseList, String> Monday;

    @FXML
    private TableColumn<CouseList, String> Tuesday;

    @FXML
    private TableColumn<CouseList, String> Wednesday;

    @FXML
    private TableColumn<CouseList, String> Thursday;

    @FXML
    private TableColumn<CouseList, String> Friday;

    @FXML
    private TableColumn<CouseList, String> Saturday;

    @FXML
    private TableColumn<CouseList, String> Sunday;

    @FXML
    private Button search;

    @FXML
    private ChoiceBox<String> collegeSelected;

    @FXML
    private TextField teacher;

    ObservableList<CouseList> list= FXCollections.observableArrayList();//用于一条条展示课表的列表
    String collSelected,teachername;
    String[] collegeName={"计算机学院","数学学院","艺术学院","经济学院","法学院","文学与新闻学院","外国语学院","马克思学院","历史文化学院（旅游学院）","国际关系学院","哲学系","物理学院"
            ,"化学学院","生命科学学院","电子信息学院","高分子科学与工程学院","材料科学与工程学院","机械工程学院","电气工程学院","建筑与环境学院","水利水电学院","化学工程学院"
            ,"轻工科学与工程学院","生物医学工程学院","软件学院","匹兹堡学院","空天科学与工程学院","网络空间安全学院","商学院","公共管理学院","灾后重建与管理学院","华西基础医学与法医学院"
            ,"华西临床学院","华西口腔学院","华西公共卫生学院","华西药学院","华西动物中心","联合班","数学学院与经济学院","吴玉章学院","生物治疗国家重点实验室","碳中和技术创新班","研究生院"
            ,"预科教育","体育学院","党委武装部（军事教研室）","网络教育学院","图书馆","分析测试中心","工程设计中心","工程训练中心","电子实习中心","电工电子中心","化学基础实验教学中心"
            ,"计算机基础教学实验中心","招生就业处","校团委","心理健康教育中心","国家大学科技园","海外教育学院","国际合作与交流处","实验室及设备管理处","现代教育技术中心","IBM技术中心"
            ,"文化科技协同创新研发中心","出国留学人员培训部","中国西部边疆安全与发展协同创新中心","成都美国留学中心","创新教育","党委学生工作部（处）","其他"};


    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {
        Ttble.setVisible(false); //先让表格不可见
        collegeSelected.getItems().addAll(collegeName);

        collegeSelected.setOnAction(this::getCollegeSelected); //得到选的哪个学院

        //在这个地方把表格的每一个column的名字设置到对应的名字，由于存在CourseList类，程序会到CourseList类中按照这里设定的名字寻找get函数，得到要打印的值
        Monday.setCellValueFactory(new PropertyValueFactory<>("MonC"));
        Tuesday.setCellValueFactory(new PropertyValueFactory<>("TueC"));
        Wednesday.setCellValueFactory(new PropertyValueFactory<>("WedC"));
        Thursday.setCellValueFactory(new PropertyValueFactory<>("ThurC"));
        Friday.setCellValueFactory(new PropertyValueFactory<>("FriC"));
        Saturday.setCellValueFactory(new PropertyValueFactory<>("SatC"));
        Sunday.setCellValueFactory(new PropertyValueFactory<>("SunC"));

        Ttble.setItems(list);
    }

    public void getCollegeSelected(ActionEvent event)
    {
        collSelected=collegeSelected.getValue();
    }

    @FXML
    void showTeacherSchedule(ActionEvent event) {
        list.clear();

        teachername=teacher.getText(); //得到老师叫啥名

        String[]  Moncou=MysqlConn.getTeacherSchedule(collSelected,teachername,"1");
        String[]  Tuecou=MysqlConn.getTeacherSchedule(collSelected,teachername,"2");
        String[]  Wedcou=MysqlConn.getTeacherSchedule(collSelected,teachername,"3");
        String[]  Fricou=MysqlConn.getTeacherSchedule(collSelected,teachername,"5");
        String[]  Thurcou=MysqlConn.getTeacherSchedule(collSelected,teachername,"4");
        String[]  Satcou=MysqlConn.getTeacherSchedule(collSelected,teachername,"6");
        String[]  Suncou=MysqlConn.getTeacherSchedule(collSelected,teachername,"7");

        for(int i=0;i<10;i++)
        {
            list.add(new CouseList(Moncou[i],Tuecou[i],Wedcou[i],Thurcou[i],Fricou[i],Satcou[i],Suncou[i]));
        }
        Ttble.setVisible(true);
    }
    /*
=================================================================以下是界面转换====================================================================
     */

    @FXML
    void SwitchToNotePage(ActionEvent event) {
        SceneManager.SwitchToNotePage(event);
    }

    @FXML
    void SwitchToSearchRoomTtblePage(ActionEvent event) {
        SceneManager.SwitchToSearchRoomTtblePage(event);
    }

    @FXML
    void SwitchToSearchTeacherTtblePage(ActionEvent event) {
        SceneManager.SwitchToSearchTeacherTtblePage(event);
    }

    @FXML
    void showSchedulePage(ActionEvent event) {
        SceneManager.SwitchToSchedulePage(event);
    }


}
